package cc.rico.es.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @Author rico
 * @Date 2019-09-22 19:53
 * @Version 1.0
 * @Description
 */
@Slf4j
public class RestHighLevelClientUtil {
    private static final String host = "192.168.17.130";
    private static int port = 9200;
    private static String schema = "http";

    public static RestHighLevelClient getInstance() {
        log.info("===============================================init RestHighLevelClient===============================================");
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, schema)));
    }

    public static void close(RestHighLevelClient client) throws IOException {
        log.info("===============================================close RestHighLevelClient===============================================");
        if(client != null) {
            client.close();
        }
    }

}
